import { httpTauri } from "@/utils/http";
import { localServer } from "@/api/utils";
import { Result } from "@/api/common";

export interface Sensor {
  deviceId: string;
  name: string;
  period: string;
}
export interface SettingIF {
  key: string;
  id: string;
  name: string;
  duration: string;
  startTime: string;
  optionY: [
    { name: "Y1"; mesure: string; sensors: Sensor[] | [] },
    { name: "Y2"; mesure: string; sensors: Sensor[] | [] }
  ];
}

export interface instanceMockForm {
  expInstId: string;
  devId: string;
  startTime: string;
  duration: string;
  period: string;
}
export interface ContorDevice {
  expId: string;
  deviceId: string;
  name: string;
  autoMode: string;
  opening: number;
  temperature: number;
  autoConfig: string;
  nowOpening: number;
  nowTemp: number;
  model: string;
}

export const getInstanceMock = async (data: instanceMockForm) => {
  return httpTauri.request<Result<object>>(
    "get",
    localServer(
      `/api/experiment/instance/data/mock/fetch?expInstId=${data.expInstId}&devId=${data.devId}&duration=${data.duration}&period=${data.period}`
    )
  );
};

export const getInstanceData = async (data: instanceMockForm) => {
  return httpTauri.request<Result<object>>(
    "get",
    localServer(
      `/api/experiment/instance/data/fetch?expInstId=${data.expInstId}&devId=${data.devId}&duration=${data.duration}&period=${data.period}&startTime=${data.startTime}`
    )
  );
};
export const exportInstanceData = async (data: object) => {
  return httpTauri.request<Result<object>>(
    "post",
    localServer(`/api/experiment/instance/data/export`),
    { data }
  );
};

export const downloadInstanceData = async (data: object) => {
  return httpTauri.request<Result<object>>(
    "get",
    localServer(
      `/api/experiment/instance/data/download?expInstId=${data.expInstId}`
    ),
    { responseType: "blob" }
  );
};
